package com.sanley.piss.web.controller;

import com.sanley.piss.model.exceptionUtil.json.JsonResult;
import com.sanley.piss.model.vo.ArchivesVO;
import com.sanley.piss.web.service.mapper.IArchivesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Create By  on 2021/3/13.
 *
 * @author 张凯大天才
 */
@Api(value = "档案表controller", tags = "档案表操作接口")
@RestController
@RequestMapping("archives")
public class ArchivesController {
    @Autowired
    private IArchivesService service;

    @ApiOperation(value = "根据基本信息表ID插入一条记录")
    @ApiImplicitParams
            ({@ApiImplicitParam(name = "userId", value = "对应用户基本信息ID", paramType = "path", required = true),
                    @ApiImplicitParam(name = "dicDataName", value = "对应数据字典类型名称")})
    @RequestMapping(value = "/{userId}/insert", method = RequestMethod.PUT)
    public JsonResult insert(@PathVariable("userId") Integer userId, @Valid ArchivesVO archives) {
        service.insert(archives, userId);
        return JsonResult.success();
    }

    @ApiOperation(value = "根据ID删除多条数据")
    @RequestMapping(value = "/delete/{ids}", method = RequestMethod.DELETE)
    public JsonResult deleteById(@PathVariable("ids") Integer[] ids) {
        service.removeByIds(ids);
        return JsonResult.success();
    }

    @ApiOperation(value = "根据ID修改一条记录")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JsonResult<Object> updateById(@Valid ArchivesVO archives) {
        service.updateById(archives);
        return JsonResult.success();
    }

    @ApiOperation(value = "查询该用户注册的所有记录")
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public JsonResult<List<ArchivesVO>> selectAll() {
        return JsonResult.success(service.selectAll());
    }

    @ApiOperation(value = "查询该用户注册的一条ID记录")
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public JsonResult<ArchivesVO> selectId(Integer id) {
        return JsonResult.success(service.selectById(id));
    }


}
